import { defineStore } from 'pinia'
import type { UseNetwork } from '@/types'

/**
 *
 */
const useNetwork: UseNetwork = defineStore('network', () => {
  const state = reactive({
    isConnected: true,
    networkType: '',
  })

  // #ifdef WEB
  state.isConnected = true
  // #endif
  // #ifndef WEB
  uni.onNetworkStatusChange((res) => {
    state.isConnected = res.isConnected
    state.networkType = res.networkType
  })
  // #endif
  return state
})

export default useNetwork
